# -*- coding: utf-8 -*-
import unittest
from selenium import webdriver
import time
import xlrd
from venv1.Public.readexcel import excel_action
from venv1.Public.xlsx_utils import XlsxUtils
from venv1.Page.loginPage import loginPage
from venv1.publicModule.login import login
from venv1.Page.menuPage import menuPage
from venv1.publicModule.inquery import inquery

from venv1.Page.paperConfirmPage import paperconfirm
from venv1.Public.xlsx_utils import XlsxUtils
from selenium.webdriver.support.ui import WebDriverWait
import traceback

class paperConfirm_case(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.driver = webdriver.Chrome()
        time.sleep(2)
        self.driver.maximize_window()
        self.driver.get("http://10.22.26.74:8080/dist/index.html#/")
        self.loginPage = loginPage(self.driver)
        self.login = login(self.driver)
        self.menupage = menuPage(self.driver)
        self.inquery = inquery(self.driver)
        self.paperconfim = paperconfirm(self.driver)
    #登录
    def test01(self):
        time.sleep(3)
        self.login.login("tracy.wang", "123456")
    def test02(self):
        time.sleep(2)
        # 读取iscan生成的单号
        filename = r"..\TestData\iscanData.xlsx"
        excelread = xlrd.open_workbook(filename)
        table = excelread.sheet_by_name('Sheet1')
        h = table.nrows
        rownumber = 1
        for i in range(2, h):
            rownumber = rownumber + 1
            excel = excel_action()
            list_data = excel.read_excel_row(filename, 0, i)
            self.inquery.Assign_To(list_data[4])
            time.sleep(3)
            self.menupage.newPaperConfirm().click()
            time.sleep(1)
            self.paperconfim.policyNo().send_keys(list_data[4])
            time.sleep(1)
            self.paperconfim.check().click()
            time.sleep(1)
            self.paperconfim.checkResult().click()
            time.sleep(3)
            windowin = self.driver.window_handles
            self.driver.switch_to.window(windowin[-1])
            time.sleep(1)
            self.paperconfim.next().click()
            time.sleep(3)
            windowin = self.driver.window_handles
            self.driver.switch_to.window(windowin[-1])
            time.sleep(3)
            self.paperconfim.productNext().click()
            time.sleep(2)
            windowin = self.driver.window_handles
            self.driver.switch_to.window(windowin[-1])
            time.sleep(2)
            self.paperconfim.commit().click()
            time.sleep(3)
            self.paperconfim.confirm().click()
            time.sleep(1)

            xlutil = XlsxUtils()
            time.sleep(2)
            xlutil.set_sheet_value(filename=filename, sheetname="Sheet1", row=rownumber + 1, col=103, value="复核通过")


